//
//  AlertUtils.m
//  RJETGeography
//
//  Created by RJET04 on 2023/8/23.
//

#import "AlertUtils.h"

@implementation AlertUtils


+ (void)showAlertMsg:(NSString *)msg sureAction:(SureAction)sureAction
        cancelAction:(CancelAction)cancelAction
                  vc:(UIViewController *)vc
                 env: (NSString *)env
{
    
    UIAlertController *ac = [UIAlertController alertControllerWithTitle:msg message:@"" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *a1 = [UIAlertAction actionWithTitle:[env isEqualToString:@"zh"] ? @"确定" : @"sure"
                                                 style:UIAlertActionStyleDefault
                                               handler:^(UIAlertAction * _Nonnull action) {
        sureAction();
    }];
//    UIAlertAction *a2 = [UIAlertAction actionWithTitle:NSLocalizedString(@"cancel", @"") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
//        cancelAction();
//    }];
    [ac addAction:a1];
//    [ac addAction:a2];
    [vc presentViewController:ac animated:YES completion:nil];
}

+ (BOOL)checkWxInstall:(UIViewController *)vc
                   env: (NSString *)env
{
    if (![WXApi isWXAppInstalled]) {
        [self showAlertMsg:[env isEqualToString:@"zh"] ? @"请先安装微信": @"Please install Weixin"
                sureAction:^{
            
            
        } cancelAction:^{
            
        } vc:vc env:env];

        return NO;
    }
    
    return YES;
}

+ (BOOL)checkZfbInstall:(UIViewController *)vc
                   env: (NSString *)env
{
    if (![[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"alipay://"]]) {
        
        [self showAlertMsg:[env isEqualToString:@"zh"] ? @"请先安装支付宝": @"Please install Alipay"
                sureAction:^{
            
            
        } cancelAction:^{
            
        } vc:vc env:env];

        return NO;
    }
    
    return YES;
}

@end
